package com.jsong.linuo.interfacetest.comparator;

import java.util.Comparator;

/**
 * @Author: 黎诺
 * @CreateTime: 2025-04-29
 * @Description: 学生
 */

public class Student implements Comparator {
    private String name;
    private int score;

    public Student() {
    }

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    /**
     * 如果o1大于o2的分数->compare方法返回正整数
     * 如果o1大于o2的分数->compare方法返回负整数
     * 如果o1大于o2的分数->compare方法返回0
     * @param o1
     * @param o2
     * @return int
     */
    @Override
    public int compare(Object o1, Object o2) {
        Student s1 = (Student) o1;
        Student s2 = (Student) o2;
        return s1.getScore()-s2.getScore();
    }
}
